import React, { useEffect } from 'react'
import { Form, Radio, Button, Select, message } from 'antd'
import { updateShops } from "../service"
const ReportSettings = ({ upload_config, Update }) => {
    const [form] = Form.useForm();

    console.log("上报", upload_config)

    useEffect(() => {
        form.setFieldsValue(upload_config)
    }, [upload_config])

    const BarrierGate = [
        {
            label: "不启用",
            vlaue: "0"
        },
        {
            label: "闸机刷卡上报",
            vlaue: "1"
        },
        {
            label: "闸机过红外上报",
            vlaue: "2"
        }
    ]


    const Save = () => {
        form.validateFields().then(values => {
            console.log(values)
            Update("upload_config", JSON.stringify(values))
        })
    }

    return (
        <div style={{ marginTop: '3vh' }}>
            <div
                style={{ fontSize: '20px', fontWeight: '550', margin: "30px" }}
            >上报信息设置</div>
            <Form
                name="basic"
                labelCol={{ span: 7 }}
                wrapperCol={{ span: 16 }}
                style={{ maxWidth: 650 }}
                autoComplete="off"
                form={form}
            >
                <Form.Item
                    label="道闸上报"
                    name="isdaozha"
                    initialValue={1}
                >
                    <Select showSearch placeholder="道闸上报">
                        {BarrierGate.map(item => (
                            <Select.Option key={item.vlaue} value={item.vlaue}>{item.label}</Select.Option>
                        ))}
                    </Select>
                </Form.Item>

                <Form.Item
                    label="授权后第一次开锁上报"
                    name="isfirstopen"
                    initialValue={"1"}
                >

                    <Select>
                        <Select.Option value="1">上报</Select.Option>
                        <Select.Option value="0">不上报</Select.Option>
                    </Select>

                </Form.Item>

                <Form.Item
                    label="授权结束是否上报"
                    name="isshouquan"
                    initialValue={"1"}
                >
                    <Select>
                        <Select.Option value="1">上报</Select.Option>
                        <Select.Option value="0">不上报</Select.Option>
                    </Select>

                </Form.Item>
                <Form.Item
                    label="柜锁低电压上报 (4.8V以下)"
                    name="islowpow"
                    initialValue={"2"}
                >
                    <Select>
                        <Select.Option value="1">上报</Select.Option>
                        <Select.Option value="0">不上报</Select.Option>
                    </Select>
                </Form.Item>
                <Form.Item
                    label="开锁上报"
                    name="isopenlock"
                    initialValue={"2"}
                >
                    <Select>
                        <Select.Option value="1">上报</Select.Option>
                        <Select.Option value="0">不上报</Select.Option>
                    </Select>

                </Form.Item>

                <Form.Item
                    label="关联初次开锁"
                    name="isclosef4"
                    initialValue={1}
                >
                    <Radio.Group

                        options={[
                            { value: "1", label: '关联' },
                            { value: "0", label: '不关联' },

                        ]}
                    />
                </Form.Item>



                <Form.Item wrapperCol={{ offset: 7, span: 16 }}>
                    <Button type="primary" htmlType="submit" onClick={Save}>
                        保存并设置
                    </Button>

                </Form.Item>
            </Form>


        </div>
    )
}

export default ReportSettings